ref(kafka): [Queue Instrumentation 20] Log Kafka instrumentation failures#5315
Draft
adinauer wants to merge 1 commit intoref/queue-instrumentation-kafka-sample-autoconfigfrom
Draft
Conversation
…ures Previously `SentryKafkaProducerInterceptor.onSend(...)` and `SentryKafkaConsumerTracing` silently swallowed any `Throwable` thrown while instrumenting a Kafka record. That protects customer Kafka I/O from breakage, but makes instrumentation bugs invisible. Log each caught `Throwable` to the SDK logger at `SentryLevel.ERROR` (matching the existing pattern in `RequestPayloadExtractor`) before continuing the fail-open path: - `SentryKafkaProducerInterceptor`: producer span creation / header injection - `SentryKafkaConsumerTracing`: scope fork + `makeCurrent`, transaction start, transaction finish No behavior change for customer callbacks or Kafka send/receive: the catches still swallow the throwable, they now just surface it via the SDK's own logger. `SentryKafkaRecordInterceptor` (Spring) was reviewed and intentionally left as-is — it does not wrap its instrumentation in `catch (Throwable)` blocks, so there is nothing silent to log. The `NumberFormatException` branches on malformed `sentry-task-enqueued-time` headers are expected input, not instrumentation faults, and remain silent.
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. This PR will not appear in the changelog. 🤖 This preview updates automatically when you update the PR. |
This was referenced Apr 21, 2026
📲 Install BuildsAndroid
|
Draft
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Stack (Queue Instrumentation)
📜 Description
Log
Throwables caught inside Kafka instrumentation instead of silently swallowing them.Affected catch sites:
SentryKafkaProducerInterceptor.onSend(...)— wrapping span creation and header injection.SentryKafkaConsumerTracing.withTracingImpl(...)— forking scopes +makeCurrent().SentryKafkaConsumerTracing.startTransaction(...)— transaction creation.SentryKafkaConsumerTracing.finishTransaction(...)— transaction finish.All catches still swallow the throwable so instrumentation failures never break the customer's Kafka send or record processing. The only change is that the failure is now reported to the SDK's own logger at
SentryLevel.ERROR(same pattern already used inRequestPayloadExtractor).SentryKafkaRecordInterceptor(Spring Jakarta) was audited alongside — it does not wrap instrumentation incatch (Throwable)blocks, so there is nothing silent to log. The existingNumberFormatExceptionbranches on malformedsentry-task-enqueued-timeheaders are expected input, not instrumentation faults, and remain silent both in the Spring interceptor and inSentryKafkaConsumerTracing.receiveLatency(...).💡 Motivation and Context
The raw Kafka instrumentation in
sentry-kafkadeliberately fails open: if anything throws while Sentry tries to start/finish a span or inject tracing headers, the customer's Kafka operation still succeeds. That behavior is correct and is preserved here.What was missing was any trace of such a failure. With
catch (Throwable ignored), an instrumentation bug would be invisible in production — neither the customer nor us would know the SDK was quietly failing. Surfacing it through the SDK logger matches how other integrations report unexpected internal failures (e.g.RequestPayloadExtractorin Spring Jakarta) and makes these paths debuggable without changing fail-open semantics.💚 How did you test it?
./gradlew :sentry-kafka:compileJava— clean../gradlew :sentry-kafka:test— all tests pass, including the existingSentryKafkaConsumerTracingTestandSentryKafkaProducerInterceptorTestsuites../gradlew spotlessApply apiDump— clean.Behavior verified by reading: catches still swallow the throwable and fall back exactly as before; only additional effect is a single
logger.log(ERROR, msg, t)call per caught throwable.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
If the
NumberFormatExceptionheader-parse branches ever prove useful to debug, they could be downgraded toDEBUGlogs. Leaving silent for now since a malformedsentry-task-enqueued-timeheader is a data-shape issue, not an SDK fault.#skip-changelog